import axios from 'axios';
const axiosInstance = axios.create({
    baseURL: 'http://localhost:9090',
    timeout: 5000,
});
axiosInstance.interceptors.request.use(
    //自动携带token
    function (config) {
        if (localStorage.getItem('token')=== null || localStorage.getItem('token') === undefined || localStorage.getItem('token') === ''){
            window.location.href = '/';
            return config;
        }
        config.headers.token= localStorage.getItem('token');
        return config;
    },
    function (error) {
        return Promise.reject(error);
    }
);
axiosInstance.interceptors.response.use(
    //检查是否登录
    function (response) {
        if (response.data===401){
            console.log('token失效');
            window.location.href = '/';
        }
        return response;
    },
    function (error) {
        return Promise.reject(error);
    }
);
export default axiosInstance;